package stream;

import java.util.stream.Stream;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/5/6
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.println("-------------of() 方法--------------");
        Stream<Integer> stream = Stream.of(1,2,7,10,20);
        stream.forEach(s-> System.out.print(s+"\t"));
        System.out.println();
        System.out.println("-------------iterate()方法-----------");
        Stream.iterate(1, n -> n + 2)
                .limit(5)
                .forEach(s-> System.out.print(s+"\t"));
        System.out.println();
        System.out.println("-------------generate() 方法----------");
        Stream.generate(Math::random)
                .limit(5)
                .forEach(s-> System.out.print(s+"\t"));
        System.out.println();
        System.out.println("-------------findFirst() 方法----------");
        Integer first = Stream.of(2,3,4,6,1,7)
                .findFirst()
                .orElse(null);
        System.out.println("第一个元素：" + first);
        System.out.println();
        System.out.println("-------------findAny() 方法----------");
        Integer any = Stream.of(8,2,3,7,8)
                .parallel()
                .findAny()
                .orElse(null);
        System.out.println("任意元素：" + any);
        System.out.println();
        System.out.println("--------------anyMatch() 方法---------");
        boolean Evens = Stream.of(1,5,1,7,5,1,3)
                .anyMatch(n -> n % 2 == 0);
        System.out.println("集合中是否包含偶数：" + Evens);
        System.out.println("----------------distinct() 方法---------");
        Stream.of(6, 7, 3, 8, 1, 2, 9, 6, 7)
                .distinct()
                .forEach(s-> System.out.print(s+"\t"));
    }
}
